<!-- 子组件 Child.vue -->
<template>
  <button @click="handleClick">点击向父组件传值</button>
</template>

<script setup>
const emit = defineEmits(['sendData']); // 声明可触发的事件
const handleClick = () => {
  emit('sendData', '子组件传递的消息', { id: 123 }); // 触发事件并携带数据
};
</script>

<!-- 父组件 Parent.vue -->
<template>
  <Child @sendData="handleReceive" />
  <p>子组件传递的数据：{{ childMsg }} - {{ childObj.id }}</p>
</template>

<script setup>
import Child from './Child.vue';
import { ref } from 'vue';
const childMsg = ref('');
const childObj = ref({});
const handleReceive = (msg, obj) => {
  childMsg.value = msg;
  childObj.value = obj;
};
</script>